<template>
    <el-menu
      :default-active="$route.path"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      @select="handleSelect">
      <!-- 修改菜单项的index为路由路径 -->
      <!-- <el-submenu index="/nested">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>导航一</span>
        </template>
        <el-menu-item-group>
          <template slot="title">分组一</template>
          <el-menu-item index="/home">首页</el-menu-item>
          <el-menu-item index="/about">关于</el-menu-item>
        </el-menu-item-group>
        <el-menu-item-group title="分组2">
          <el-menu-item index="1-3">选项3</el-menu-item>
        </el-menu-item-group>
        <el-submenu index="1-4">
          <template slot="title">选项4</template>
          <el-menu-item index="1-4-1">选项1</el-menu-item>
        </el-submenu>
      </el-submenu> -->
      <el-submenu index="/nested">
        <template slot="title">vue2</template>
        <el-menu-item index="/child-vue2/home">home</el-menu-item>
        <el-menu-item index="/child-vue2/about">about</el-menu-item>
      </el-submenu>
      <!-- <el-menu-item index="/child-vue2/vue2">
        <i class="el-icon-menu"></i>
        <span slot="title">导航二</span>
      </el-menu-item> -->
      <el-submenu index="/2">
        <template slot="title">vue3</template>
        <el-menu-item index="/child-vue3/home">home</el-menu-item>
        <el-menu-item index="/child-vue3/about">about</el-menu-item>
      </el-submenu>
      <el-submenu index="/3">
        <template slot="title">vue3-ts</template>
        <el-menu-item index="/vue3-ts/home">home</el-menu-item>
        <el-menu-item index="/vue3-ts/about">about</el-menu-item>
      </el-submenu>
      <el-menu-item index="/child-react/react">
        <i class="el-icon-setting"></i>
        <span slot="title">导航四</span>
      </el-menu-item>
    </el-menu>
</template>

<script>
export default {
  name: 'VMenu',
  methods: {
    // 新增路由跳转方法
    handleSelect(path) {
      this.$router.push(path)
    },
    // 以下原有方法保持不变
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    }
  }
}
</script>